package org.abc.fund.entity.factorEntity;

import jakarta.persistence.*;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * Entity representing collected stock data from external data sources.
 */
@Entity
@Table(name = "collected_stock_data", indexes = {
        @Index(name = "idx_symbol_date", columnList = "symbol, trade_date"),
        @Index(name = "idx_source", columnList = "data_source")
})
@Data
public class CollectedStockData {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * Stock symbol (e.g., "000001.SZ")
     */
    @Column(nullable = false, length = 20)
    private String symbol;

    /**
     * Trading date
     */
    @Column(name = "trade_date", nullable = false)
    private LocalDate tradeDate;

    /**
     * Opening price
     */
    @Column(precision = 15, scale = 4)
    private BigDecimal openPrice;

    /**
     * Closing price
     */
    @Column(precision = 15, scale = 4)
    private BigDecimal closePrice;

    /**
     * Highest price
     */
    @Column(precision = 15, scale = 4)
    private BigDecimal highPrice;

    /**
     * Lowest price
     */
    @Column(precision = 15, scale = 4)
    private BigDecimal lowPrice;

    /**
     * Trading volume
     */
    private Long volume;

    /**
     * Data source (e.g., "WIND", "JOINQUANT")
     */
    @Column(name = "data_source", nullable = false, length = 50)
    private String dataSource;

    /**
     * Timestamp when the data was collected
     */
    @Column(name = "collected_at", nullable = false)
    private LocalDateTime collectedAt;

    @PrePersist
    protected void onCreate() {
        if (collectedAt == null) {
            collectedAt = LocalDateTime.now();
        }
    }
}


























